package com.norrisboat.di

import com.norrisboat.services.*
import com.norrisboat.utils.SocketConnection
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.plugins.logging.*
import io.ktor.serialization.kotlinx.json.*
import kotlinx.serialization.json.Json
import org.koin.dsl.module

val servicesModule = arrayOf(
    module { single<AuthService> { AuthServiceImpl() } },
    module { single<QuizService> { QuizServiceImpl() } },
    module { single<QuestionService> { QuestionServiceImpl() } },
    module { single<LiveQuizService> { LiveQuizServiceImpl() } },
    module {
        single {
            HttpClient(CIO) {
                install(ContentNegotiation) {
                    json(Json {
                        ignoreUnknownKeys = true
                        isLenient = true
                    })
                }

                install(Logging) {
                    level = LogLevel.ALL
                }
            }
        }
    }
)

val socketConnectionModule = module {
    single { SocketConnection() }
}